home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / DISPC.C < prev    next >
C/C++ Source or Header  |  1991-11-18  |  28KB  |  934 lines

  1. /*
  2.  * File......: DISPC.C
  3.  * Author....: Mike Taylor
  4.  * Date......: $Date:   18 Nov 1991 02:20:20  $
  5.  * Revision..: $Revision:   1.4  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/dispc.c_v  $
  7.  * 
  8.  * This is an original work by Mike Taylor and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/dispc.c_v  $
  15.  * 
  16.  *    Rev 1.4   18 Nov 1991 02:20:20   GLENN
  17.  * Mike fixed a bug in _ft_dfinit() related to allocating memory.  Some
  18.  * users had been reporting problems, but everyone who tested this patch
  19.  * reported success.
  20.  * 
  21.  *    Rev 1.3   17 Aug 1991 15:25:46   GLENN
  22.  * Don Caton fixed some spelling errors in the doc
  23.  * 
  24.  *    Rev 1.2   15 Aug 1991 23:08:14   GLENN
  25.  * Forest Belt proofread/edited/cleaned up doc
  26.  * 
  27.  *    Rev 1.1   14 Jun 1991 19:53:42   GLENN
  28.  * Minor edit to file header
  29.  * 
  30.  *    Rev 1.0   01 Apr 1991 01:02:46   GLENN
  31.  * Nanforum Toolkit
  32.  * 
  33.  *
  34.  */
  35.  
  36.  
  37.  
  38. #include "extend.h"
  39. #include "dfkey.h"
  40.  
  41.  
  42. #define MK_FP(seg, ofs) ((void far *) (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
  43.  
  44. #define FP_SEG(fp) (*((unsigned *)&(fp) + 1))   // copied from MSC 5.1
  45. #define FP_OFF(fp) (*((unsigned *)&(fp)))       //  include file 'dos.h'
  46.  
  47. #define OFF 0
  48. #define ON  (!OFF)
  49. #define NO  0
  50. #define YES (!NO)
  51. #define OK  0
  52.  
  53. #define CR   ((char) 13)
  54. #define LF   ((char) 10)
  55. #define FEOF ((char) 26)
  56.  
  57. #define SEEK_END 2              // file seek directions
  58. #define SEEK_CUR 1
  59. #define SEEK_SET 0
  60.  
  61. #define READONLY  0             // open file modes
  62. #define WRITEONLY 1
  63. #define READWRITE 2
  64.  
  65. #define MDASEG 0x0b000          // mono video memory segment
  66. #define CGASEG 0x0b800          // color video memory segment
  67.  
  68. #define BUFFERSIZE 4096         // maximum size of the file buffer
  69. #define MAXLINE    255          // default maximum size of a line
  70.  
  71. long buffoffset;            // offset into buffer of current line
  72. long fsize;                 // file size in bytes
  73. int  bufftop, buffbot;      // first and last character in buffer
  74. int  wintop, winbot;        // first and last character in window
  75. int  winrow, wincol;        // row and column of window highlight
  76. int  sline, eline;          // start and end line of window
  77. int  scol, ecol;            // start and end col of window
  78. int  height, width;         // height and width of window
  79. int  infile;                // input file handle
  80. int  maxlin;                // line size
  81. int  buffsize;              // buffer size
  82. int  hlight;                // highlight attribute
  83. int  norm;                  // normal attribute
  84. int  kcount;                // number of keys in terminate key list
  85. int  colinc;                // col increment amount
  86. int  brows;                 // browse flag
  87. char refresh;               // YES means refresh screen
  88. char kstr[25];              // terminate key string
  89.  
  90. char far *buffer;           // file buffer pointer
  91. char far *lbuff;            // line buffer pointer
  92. char far *vseg;             // video segment variable
  93.  
  94.  
  95.     // prototypes
  96.  
  97.  
  98. CLIPPER _ft_dfinit(void);
  99. CLIPPER _ft_dfclos(void);
  100.  
  101. unsigned char keyin(void);
  102. void          chattr(int x, int y, int len, int attr);
  103. long          getblock(long offset);
  104. void          buff_align(void);
  105. void          win_align(void);
  106. void          disp_update(int offset);
  107. void          windown(void);
  108. void          winup(void);
  109. void          linedown(void);
  110. void          lineup(void);
  111. void          filetop(void);
  112. void          filebot(void);
  113.  
  114.     // found in dispa.asm
  115.  
  116. int           _ft_fileread(int handle, char far *buffer, int bytes);
  117. long          _ft_fileseek(int handle, long offset, int direction);
  118. void          _ft_gotoxy(int x, int y);
  119. char          _ft_getkey(void);
  120. char far *    _ft_vconfig(void);
  121.  
  122.     // this is defined because I found out that CLIPPER has a version
  123.     //   strcpy linked in normally - this just shut's up the LINT check
  124.  
  125. extern char *strcpy(char far *, char far *);
  126.  
  127.  
  128. /*
  129.  * chattr() replace the color attribute with a new one starting at
  130.  * location x, y and going for length len.
  131.  *
  132.  */
  133.  
  134.  
  135. static void chattr(int x, int y, int len, int attr)
  136. {
  137.     int i;
  138.     char far *vmem;
  139.  
  140.     vmem = vseg;
  141.     FP_OFF(vmem) = (y * 160) + (x * 2) + 1;     // calc the screen memory coord
  142.  
  143.     for (i = 0; i <= len; i++, vmem += 2)       // write the new attribute value
  144.         *vmem = (char) attr;
  145. }
  146.  
  147.  
  148.  
  149.  
  150. /*
  151.  *  keyin() gets the next key typed and does any translation needed.
  152.  *  Some keys are converted to a common name - like the up arrow is
  153.  *  converted to the UP value which also is the Ctrl-E value.  This
  154.  *  allows the Wordstar-like control keys to be used.  Only extended
  155.  *  keys are translated - the values of the defines were chosen to
  156.  *  match up with the non-extended key codes.
  157.  *
  158.  */
  159.  
  160. static unsigned char keyin()
  161. {
  162.     unsigned char ch;
  163.  
  164.     ch = (unsigned char) _ft_getkey();      // get the next key
  165.  
  166.     if ( ch == 0x00 )                       // check to see if it's extended
  167.     {
  168.         ch = (unsigned char) _ft_getkey();  // if so, read the second part
  169.  
  170.         switch ( ch )                       //  and convert it
  171.         {
  172.             case 75   : ch = LFT;    break;
  173.             case 77   : ch = RGT;    break;
  174.             case 72   : ch = UP;     break;
  175.             case 80   : ch = DN;     break;
  176.             case 71   : ch = HOME;   break;
  177.             case 79   : ch = ENND;   break;
  178.             case 73   : ch = PGUP;   break;
  179.             case 81   : ch = PGDN;   break;
  180.             case 62   : ch = F4;     break;
  181.             case 117  : ch = CENND;  break;
  182.             case 119  : ch = CHOME;  break;
  183.             case 118  : ch = CPGDN;  break;
  184.             case 132  : ch = CPGUP;  break;
  185.             case 116  : ch = CRGT;   break;
  186.             case 115  : ch = CLFT;   break;
  187.             case 82   : ch = INS;    break;
  188.             case 83   : ch = DEL;    break;
  189.             case 68   : ch = F0;     break;
  190.             case 59   : ch = F1;     break;
  191.             case 60   : ch = F2;     break;
  192.             case 61   : ch = F3;     break;
  193.             case 63   : ch = F5;     break;
  194.             case 64   : ch = F6;     break;
  195.             case 65   : ch = F7;     break;
  196.             case 66   : ch = F8;     break;
  197.             case 67   : ch = F9;     break;
  198.             case 113  : ch = AF0;    break;
  199.             case 104  : ch = AF1;    break;
  200.             case 105  : ch = AF2;    break;
  201.             case 106  : ch = AF3;    break;
  202.             case 107  : ch = AF4;    break;
  203.             case 108  : ch = AF5;    break;
  204.             case 109  : ch = AF6;    break;
  205.             case 110  : ch = AF7;    break;
  206.             case 111  : ch = AF8;    break;
  207.             case 112  : ch = AF9;    break;
  208.             case 94   : ch = CF1;    break;
  209.             case 95   : ch = CF2;    break;
  210.             case 96   : ch = CF3;    break;
  211.             case 97   : ch = CF4;    break;
  212.             case 98   : ch = CF5;    break;
  213.             case 99   : ch = CF6;    break;
  214.             case 100  : ch = CF7;    break;
  215.             case 101  : ch = CF8;    break;
  216.             case 102  : ch = CF9;    break;
  217.             case 103  : ch = CF0;    break;
  218.             case 120  : ch = ALT1;   break;
  219.             case 121  : ch = ALT2;   break;
  220.             case 122  : ch = ALT3;   break;
  221.             case 123  : ch = ALT4;   break;
  222.             case 124  : ch = ALT5;   break;
  223.             case 125  : ch = ALT6;   break;
  224.             case 126  : ch = ALT7;   break;
  225.             case 127  : ch = ALT8;   break;
  226.             case 128  : ch = ALT9;   break;
  227.             case 129  : ch = ALT0;   break;
  228.             case 130  : ch = ADASH;  break;
  229.             case 131  : ch = AEQL;   break;
  230.             case 30   : ch = ALTA;   break;
  231.             case 48   : ch = ALTB;   break;
  232.             case 46   : ch = ALTC;   break;
  233.             case 32   : ch = ALTD;   break;
  234.             case 18   : ch = ALTE;   break;
  235.             case 33   : ch = ALTF;   break;
  236.             case 34   : ch = ALTG;   break;
  237.             case 35   : ch